package com.zone.vehicle.superapp.utils;

import com.saicmotor.pay.db.PayDaoUtilsStore;
import com.saicmotor.pay.db.entity.Pay;
import com.zone.lib.download.db.entity.Download;

import org.apache.commons.lang3.ObjectUtils;

/**
 * @Author: pkqlqx
 * @CreateDate: 2022/3/14 17:51
 * @Description: 应用使用权限校验
 */
public class AppUsePermission {

    public static boolean hasPermission(Download download){
        if (ObjectUtils.isEmpty(download)){
            return false;
        }
        if (!download.getIsFree()){
            //收费
            if (!LoginUtil.isLogin()){
                //未登录
                return false;
            }
            Pay pay = PayDaoUtilsStore.getInstance().getPayByCode(download.getCode(), LoginUtil.getUserId());
            if (ObjectUtils.isEmpty(pay)){
                //未创建订单
                return false;
            }
            //未付款
            return pay.getPayStatus().equals("1");
        }
        return true;
    }

}
